var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var t = require("../../@babel/runtime/helpers/classCallCheck"),
  n = require("../../@babel/runtime/helpers/createClass"),
  a = require("../../@babel/runtime/helpers/get"),
  i = require("../../@babel/runtime/helpers/getPrototypeOf"),
  o = require("../../@babel/runtime/helpers/inherits"),
  s = require("../../@babel/runtime/helpers/createSuper"),
  r = e(require("../common/EventDispatcher")),
  l = e(require("./LocationEvent")),
  u = e(require("./BeaconStatus")),
  c = e(require("./LocationHelper")),
  _ = e(require("../common/DeepClone")),
  d = require("../utils/axios"),
  h = (function (e) {
    o(h, e);
    var r = s(h);
    function h(e) {
      var n;
      t(this, h), (n = r.call(this));
      var a = "android" !== wx.getSystemInfoSync().platform,
        i = c.default.getEngine().li;
      (i.axios = d.axios),
        console.info(i.Version),
        (n._sensorManager = e.sensorManager),
        (n._floorMapper = e.floorMapper),
        (n._locationInstance = new i({
          isIOS: a,
          locateOptions: { floorMapper: n._floorMapper, isIOS: a },
          sensorManager: n._sensorManager,
        }));
      var o = n._locationInstance.getLocationVersion();
      return (
        console.warn("算法版本：" + o),
        (n._beaconStatus = u.default.INIT),
        (n._mapMatchingStatus = !0),
        (n._exceedPositionLimit = !1),
        (n._headingStatus = void 0),
        (n._lastPosition = void 0),
        n._initEvents(),
        n
      );
    }
    return (
      n(h, [
        {
          key: "dispose",
          value: function () {
            this.stop(),
              this._locationInstance.dispose(),
              (this._locationInstance._sensorManager = {}),
              a(i(h.prototype), "dispose", this).call(this),
              (this.listeners = []);
          },
        },
        {
          key: "sensorManager",
          get: function () {
            return this._sensorManager;
          },
        },
        {
          key: "getRegion",
          value: function (e, t) {
            return this._floorMapper.regionMapDecode(e, t);
          },
        },
        {
          key: "_initEvents",
          value: function () {
            var e = this;
            this._locationInstance.on("le_positionChanged", function (t) {
              if (t && t.value) {
                var n = t.value;
                if (void 0 !== n.x)
                  if (void 0 !== n.y)
                    if (void 0 !== n.z)
                      if (void 0 !== n.buildingCode) {
                        (n.region = e.getRegion(n.buildingCode, n.z)),
                          (n.mapCode = n.buildingCode),
                          (e._lastPosition = n);
                        var a = n.mapMatchingStatus;
                        void 0 !== a &&
                          a !== e._mapMatchingStatus &&
                          ((e._mapMatchingStatus = a),
                          e.emit(l.default.MATCHING_STATUS_CHANGED, {
                            value: e._mapMatchingStatus,
                          }));
                        var i = t;
                        e._exceedPositionLimit ||
                          e.emit(l.default.POSITION_CHANGED, i);
                      } else console.warn("no buildingCode", n);
                    else console.warn("no z", n);
                  else console.warn("no y", n);
                else console.warn("no x", n);
              }
            }),
              this._locationInstance.on("le_orientationChanged", function (t) {
                e.emit(l.default.ORIENTATION_CHANGED, t);
              }),
              this._locationInstance.on("le_btScanSuccess", function () {
                e._beaconStatus !== u.default.OPENED &&
                  ((e._beaconStatus = u.default.OPENED),
                  e.emit(l.default.BEACON_STATUS_CHANGED, {
                    value: e._beaconStatus,
                  }));
              }),
              this._locationInstance.on("le_btError", function () {
                e._beaconStatus !== u.default.CLOSED &&
                  ((e._beaconStatus = u.default.CLOSED),
                  e.emit(l.default.BEACON_STATUS_CHANGED, {
                    value: e._beaconStatus,
                  }));
              }),
              this._locationInstance.on("le_exceedPositionLimit", function (t) {
                e._exceedPositionLimit !== t.value &&
                  ((e._exceedPositionLimit = t.value),
                  e.emit(l.default.EXCEED_POSITION_LIMIT, t));
              }),
              this._locationInstance.on(
                "le_positionModeShouldChange",
                function (t) {
                  e.emit(l.default.POSITION_MODE_SHOULD_CHANGE, t);
                },
              ),
              this._locationInstance.on(
                "le_headingSensorStatusChanged",
                function (t) {
                  t.value !== e._headingStatus &&
                    ((e._headingStatus = t.value),
                    e.emit(l.default.HEADING_SENSOR_STATUS_CHANGED, t));
                },
              );
          },
        },
        {
          key: "instance",
          get: function () {
            return this._locationInstance;
          },
        },
        {
          key: "loadBuildingInfo",
          value: function (e) {
            try {
              this._locationInstance.loadBuildingInfo(e);
            } catch (e) {
              console.error(e);
            }
          },
        },
        {
          key: "setPosition",
          value: function (e) {
            this.instance.emit("le_positionChanged", { value: e });
          },
        },
        {
          key: "start",
          value: function () {
            this.emit("start"),
              this._locationInstance.startLocate(),
              this._sensorManager.aoaLocator &&
                this._sensorManager.aoaLocator.start();
          },
        },
        {
          key: "stop",
          value: function () {
            this.emit("stop"),
              this._locationInstance.stopLocate(),
              this._sensorManager.aoaLocator &&
                this._sensorManager.aoaLocator.stop();
          },
        },
        {
          key: "initHmm",
          value: function (e) {
            this._locationInstance.initHmm(e);
          },
        },
        {
          key: "setWalkingMode",
          value: function () {
            this._locationInstance.setWalkingMode();
          },
        },
        {
          key: "updateNavMessage",
          value: function (e) {
            this._locationInstance.updateNavMessage(e);
          },
        },
        {
          key: "setNavigationPaths",
          value: function (e) {
            this.emit("setNavigationPaths", e),
              this._locationInstance.setNavigationPaths(e);
          },
        },
        {
          key: "setARInitPos",
          value: function (e) {
            this._locationInstance.setARInitPos &&
              (console.info("setARInitPos", e),
              this.emit("setARLastPos", e),
              this._locationInstance.setARInitPos(e));
          },
        },
        {
          key: "getLastPosition",
          value: function () {
            return (0, _.default)(this._lastPosition);
          },
        },
      ]),
      h
    );
  })(r.default);
exports.default = h;
